import { Component } from '@angular/core';
import { NavController,LoadingController,ModalController} from 'ionic-angular';
import {RegisterPage} from "../register/register";
import {LoginService} from "./LoginSevice";

@Component({
  selector: 'page-login',
  templateUrl: 'login.html',
  providers:[LoginService]
})
export class LoginPage {
   public user = {  
    username: '',  
    password: ''  
  };  
  constructor(private navCtrl: NavController,private loading: LoadingController,private modalCtrl:ModalController,private loginService:LoginService) {

  }
  showFill() {  
    //alert(this.user.username);  
    //console.log(this.user.password);
    //封装一个loading的方法，等ajax之后就可以调用dismiss()方法啦
    let loading = this.presentLoading();
    let userLoginUrl = "c=index&a=checklogin";
    this.loginService.getLogin(userLoginUrl,this.user).then((res)=>{
      console.log(res);
      loading.dismiss();
    })
/*    setTimeout(()=>{
    	loading.dismiss();
    },3000)*/
  }
  goRegister(){
  	let profileModal = this.modalCtrl.create(RegisterPage,{ userId: 8675309 });
     profileModal.onDidDismiss(data => {
     console.log(data);
   });
    profileModal.present();
  }
  //loading封装一个方法
  presentLoading() {
    let loader = this.loading.create({
      content: "请稍后...",
    });
    loader.present();
    return loader;
  }
}
